package com.sk.bilibili.other;

import lombok.Data;

/**
 * @author 邵康
 * @date 2021/11/22 12:26
 */
@Data
public class R<T> {

    private T data;
    private String msg;
    private Integer code;

    private R(T data, String msg, Integer code) {
        this.data = data;
        this.msg = msg;
        this.code = code;
    }

    public static <T> R<T> success(T data){
        return new R<>(data,"成功",200);
    }

    public static <T> R<T> danmu(T data){
        return new R<>(data,"成功",0);//弹幕特殊
    }

    public static <T> R<T> success(){
        return new R<>(null,"成功",200);
    }

    public static <T> R<T> res(boolean res){
        return res?R.success():R.error();
    }

    public static <T> R<T> error(){
        return new R<>(null,"失败",500);
    }

    public static <T> R<T> error(String msg){
        return new R<>(null,msg,500);
    }

    public static <T> R<T> error(String msg,Integer code){
        return new R<>(null,msg,code);
    }

}
